package demo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2024-03-31
 * Time: 10:48
 */
public class Test1 {
    public static void main(String[] args) {
        Mystack mystack = new Mystack();
        mystack.push(1);
        mystack.push(2);
        mystack.push(3);

        System.out.println(mystack.pop());
        System.out.println(mystack.pop());
        System.out.println(mystack.pop());
        System.out.println(mystack.pop());

        public int evalRPN(String[] tokens) {
            Stack<Integer> stack = new Stack<>();

            for(int i = 0; i < tokens.length; i++) {
                if(!isOperation(tokens[i])) {
                    Integer x = Integer.valueOf(tokens[i]);
                    stack.push(x);
                }else {
                    int val2 = stack.pop();
                    int val1 = stack.pop();
                    switch(tokens[i]) {
                        case "+":
                            stack.push(val1 + val2);
                            break;
                        case "-":
                            stack.push(val1 - val2);
                            break;
                        case "*":
                            stack.push(val1 * val2);
                            break;
                        case "/":
                            stack.push(val1 / val2);
                            break;
                    }
                }
            }
            return stack.pop();
        }

        public boolean isOperation(String s) {
            if(s.equals("+") || s.equals("*") || s.equals("-") || s.equals("/")) {
                return true;
            }
            return false;
        }
        /*Integer x = Integer.valueOf("111");
        System.out.println(x);*/



    }
}
